<template>
  <div class="app-container calendar-list-container">
    <div class="filter-container">
      <el-row>
        <el-col :span="24" style="text-align: right">
          <el-input size="small" style="width: 200px" class="filter-item fsc-search" placeholder="车架号-回车查询" v-model="listQuery.condition.vin" @keyup.enter.native="searchClick"></el-input>
          <el-button class="filter-item" size="small" type="primary" v-waves icon="el-icon-search" @click="searchClick">
            搜索
          </el-button>
          <el-button class="filter-item" size="small" type="primary" v-waves icon="el-icon-circle-plus-outline" @click="moreClick">更多
          </el-button>
          <el-dropdown trigger="click" :hide-on-click=false style="float: right;margin-left: 10px">
            <span class="el-dropdown-link">
              <el-button class="filter-item" size="small" type="primary" v-waves>
                选择列
                <i class="el-icon-arrow-down el-icon--right"></i>
              </el-button>
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item>
                <el-checkbox-group v-model="theadCheckVal">
                  <el-checkbox label="orderNo">订单号</el-checkbox>
                  <el-checkbox label="vin">车架号</el-checkbox>
                  <!--<el-checkbox label="qrCode">二维码</el-checkbox>-->
                  <el-checkbox label="taskType">任务类型</el-checkbox>
                  <el-checkbox label="taskStatus">任务状态</el-checkbox>
                  <el-checkbox label="originName">起始地</el-checkbox>
                  <el-checkbox label="destName">目的地</el-checkbox>
                  <el-checkbox label="stanVehicleType">车型</el-checkbox>
                  <el-checkbox label="driverName">司机姓名</el-checkbox>
                  <!--<el-checkbox label="driverPhone">司机电话</el-checkbox>-->
                  <el-checkbox label="startTime">开始时间</el-checkbox>
                  <el-checkbox label="finishTime">完成时间</el-checkbox>
                </el-checkbox-group>
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>
      <div style="clean:both"></div>
    </div>

    <div :class="{'search-transition':searchFlag,h0:true,hAuto:searchFlag,'search-content':true}">
      <el-form ref="form" :model="listQuery.condition" label-width="80px" :inline="true">
        <el-form-item label=订单号:>
          <el-input  placeholder="请输入订单号" class="w200" clearable v-model="listQuery.condition.orderNo" ></el-input>
        </el-form-item>
        <el-form-item label=任务类型:>
          <el-select v-model="listQuery.condition.taskType" placeholder="请选择任务类型">
            <el-option label="寻车" value="10"></el-option>
            <el-option label="移车" value="20"></el-option>
            <el-option label="提车" value="30"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label=任务状态:>
          <el-select v-model="listQuery.condition.taskStatus" placeholder="请选择任务状态">
            <el-option label="创建" value="10"></el-option>
            <el-option label="开始" value="20"></el-option>
            <el-option label="完成" value="30"></el-option>
            <el-option label="取消" value="50"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="登记时间:">
          <el-date-picker class="w200" v-model="listQuery.condition.startDate" type="datetime" placeholder="选择日期时间"  value-format="yyyy-MM-dd HH:mm:ss"
                          align="right" :picker-options="timePicker"></el-date-picker>
          <span style="padding: 0 6px">至</span>
          <el-date-picker class="w200" v-model="listQuery.condition.endDate" type="datetime" placeholder="选择日期时间"  value-format="yyyy-MM-dd HH:mm:ss"
                          align="right" :picker-options="timePicker"></el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="searchClick" style="margin-left: 10px">查询</el-button>
          <el-button type="primary" @click="reset">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div style="clean:both"></div>
    <el-table ref="expectionTable" :data="taskList" v-loading="listLoading" element-loading-text="加载中" border fit highlight-current-row style="width: 100%;margin-top:5px">
      <el-table-column type="selection" width="35"></el-table-column>
      <el-table-column :key="key" align="center" :width="value.width" v-for='(value,key) in tableThead' :label="value.title">
        <template slot-scope="scope">
          <div v-if="value.key === 'taskType'">{{scope.row[value.key] | taskTypeFilter}}</div>
          <div v-else-if="value.key === 'taskStatus'">{{scope.row[value.key] | taskStatusFilter}}</div>
          <div v-else>{{scope.row[value.key]}}</div>
        </template>
      </el-table-column>
    </el-table>
    <div v-show="!listLoading" class="pagination-container">
      <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page.sync="listQuery.current" :page-sizes="[10,20,30,50]" :page-size="listQuery.size" layout="total, sizes, prev, pager, next, jumper" :total="listQuery.total">
      </el-pagination>
    </div>
  </div>
</template>
<script>
  import * as taskAPI from '@/api/pick/task'
  import waves from '@/directive/waves' // 水波纹指令
  const defautlTableThead = [
    { key: 'orderNo', title: '订单号', width: '' },
    { key: 'vin', title: '车架号', width: '' },
    // { key: 'qrCode', title: '二维码', width: '' },
    { key: 'taskType', title: '任务类型', width: 106 },
    { key: 'taskStatus', title: '任务状态', width: 106 },
    { key: 'originName', title: '起始地', width: '' },
    { key: 'destName', title: '目的地', width: '' },
    { key: 'stanVehicleType', title: '车型', width: '' },
    { key: 'driverName', title: '司机姓名', width: '' },
    // { key: 'driverPhone', title: '司机电话', width: '' },
    { key: 'startTime', title: '开始时间', width: 160 },
    { key: 'finishTime', title: '完成时间', width: 160 }
  ]
  export default {
    name: 'task',
    directives: {
      waves
    },
    data() {
      return {
        theadCheckVal: [
          'orderNo',
          'vin',
          // 'qrCode',
          'taskType',
          'taskStatus',
          'originName',
          'destName',
          'stanVehicleType',
          'driverName',
          // 'driverPhone',
          'startTime',
          'finishTime'
        ],
        tableThead: defautlTableThead,
        listQuery: {
          current: 1,
          size: 10,
          total: 0,
          condition: {}
        },
        taskList: [],
        listLoading: true,
        searchFlag: false,
        timePicker: {
          shortcuts: [{
            text: '今天',
            onClick(picker) {
              picker.$emit('pick', new Date())
            }
          }, {
            text: '昨天',
            onClick(picker) {
              const date = new Date()
              date.setTime(date.getTime() - 3600 * 1000 * 24)
              picker.$emit('pick', date)
            }
          }, {
            text: '一周前',
            onClick(picker) {
              const date = new Date()
              date.setTime(date.getTime() - 3600 * 1000 * 24 * 7)
              picker.$emit('pick', date)
            }
          }]
        }
      }
    },
    created() {
      this.list()
    },
    watch: {
      theadCheckVal(valArr) {
        this.tableThead = defautlTableThead.filter(v => {
          for (var i = 0; i < valArr.length; i++) {
            if (v.key === valArr[i]) {
              return v
            }
          }
        })
      }
    },
    methods: {
      list() {
        // 列表查询
        this.listLoading = true
        // 处理是否展开更多
        let queryParam = {}
        if (this.$data.searchFlag) {
          queryParam = this.$data.listQuery
        } else {
          Object.assign(queryParam, this.$data.listQuery)
          queryParam.condition = {
            vin: this.$data.listQuery.condition.vin
          }
        }
        // queryParam.condition.houseId = this.$store.getters.currentStorehouse.id
        taskAPI.getTaskList(queryParam).then(result => {
          if (result.code === 0) {
            this.$data.taskList = result.data.records
            this.$data.listQuery.total = result.data.total
            this.listLoading = false
          } else {
            this.listLoading = false
            this.$notify({
              title: '信息提示',
              message: result.message,
              type: 'error',
              duration: 2000
            })
          }
        })
      },
      handleSizeChange(val) {
        // 分页size变化
        this.$data.listQuery.size = val
        this.list()
      },
      handleCurrentChange(val) {
        // 分页当前页变化
        this.$data.listQuery.current = val
        this.list()
      },
      moreClick() {
        // 更多click
        this.$data.searchFlag = !this.$data.searchFlag
      },
      searchClick() {
        // 搜索
        this.list()
      },
      reset() {
        this.$data.listQuery.condition = {
          // houseId: this.$store.getters.currentStorehouse.id,
          vin: null,
          orderNo: null,
          taskType: null,
          taskStatus: null,
          startDate: null,
          endDate: null
        }
        this.list()
      }
    }
  }
</script>
<style scoped>

</style>
